home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / App.js < prev    next >
Encoding:
JavaScript  |  2002-10-22  |  45.2 KB  |  1,428 lines

  1.  
  2.  
  3. // XXX Global to determine if our onload handler has been called yet.
  4. // For some reason, our onunload handler is getting called before onload
  5. // on the first time we create App.xul. This is a workaround.
  6. var gFirstTime = 1;
  7. var timercatch = false;
  8.  
  9. function GoAway( target )
  10. {
  11.     var name = target.getAttribute('MsgText');
  12.     if(name=='')
  13.     {
  14.         try 
  15.         {
  16.           name= document.getElementById('tbAway').getElementsByTagName("menuitem")[1].getAttribute('MsgText')
  17.         }
  18.         catch (e)
  19.         {
  20.             //Some error finding tbAway message-Setting default backup message
  21.             name=aimString("away.DefaultMessage");
  22.         }
  23.     }
  24.  
  25.     locateManager = aimLocateManager();
  26.   if (locateManager)
  27.         locateManager.SetUserInfoAwayMessage(name);
  28. }
  29.  
  30. var targetElement = null;
  31.  
  32. function GoAwayWait(target,wait)
  33. {
  34.     targetElement = target;
  35.     setTimeout('GoAway( targetElement )',wait)
  36. }
  37.  
  38. /*
  39.  * Function: AimAppOnWndLoad()
  40.  *
  41.  * Arguments: None
  42.  * 
  43.  * Return: None
  44.  *
  45.  * Description: Called once app.xul has finished loading.Initializes the
  46.  *        sidebar.
  47. */
  48.  
  49. function AimAppOnWndLoad()
  50. {
  51.   // XXX See note at the top of the file
  52.     gFirstTime = 0;
  53.  
  54.     setTimeout("CheckBuddyPanel()",500);
  55.     
  56.   setAdTimer();
  57.  
  58.   updateCurrentAppWindow();
  59.  
  60.   addAppSessionListener();
  61.  
  62.   setTimeout("aimSession().SetAppIcon()", 1000);
  63.  
  64.  
  65. }
  66.  
  67. /*
  68.  * Function: AimAppOnWndUnload()
  69.  *
  70.  * Arguments: None
  71.  * 
  72.  * Return: None
  73.  *
  74.  * Description: Called once app.xul has been unloaded. 
  75. */
  76.  
  77. function AimAppOnWndUnload()
  78. {
  79.     // XXX See note at the top of the file
  80.  
  81.   if(gFirstTime == 1)
  82.         return;
  83.   removeAppSessionListener();
  84. }
  85.  
  86. //************  Command Handling ****************
  87.  
  88. /*
  89.  * Function: cmdNewBrowser()
  90.  *
  91.  * Arguments: None
  92.  * 
  93.  * Return: None
  94.  *
  95.  * Description: Function invoked from menu or toolbar to create a new 
  96.  *         browser window. 
  97.  * 
  98.  * Bugs: URL is hardcoded. Needs to open a user-specified preference.
  99. */
  100.  
  101. function cmdNewBrowser()
  102. {
  103.     aimCmdNewBrowser("http://home.netscape.com");
  104. }
  105.  
  106. /*
  107.  * Function: cmdNewEmail()
  108.  *
  109.  * Arguments: None
  110.  * 
  111.  * Return: None
  112.  *
  113.  * Description: Function invoked from menu or toolbar to create a new
  114.  *        messenger window. 
  115. */
  116.  
  117. function cmdNewEmail()
  118. {
  119.     aimCmdNewEmail();
  120. }
  121.  
  122.  
  123.  
  124. function cmdNewChat(invScreenName,invProposal,invScreenNames,toExistingWindow,invMode)
  125. {
  126.   if (isIcq() != true )
  127.   {
  128.     //App is aim - in this case shift-ctrl-C which invokes cmdNewchat should bring up chat window
  129.   inviteArgsObj = {
  130.     inviteProposalScreenName: invScreenName, 
  131.     inviteProposalObj: invProposal,
  132.     invitedScreenNames: invScreenNames,
  133.     inviteToExistingWindow: toExistingWindow,
  134.     inviteMode: invMode
  135.   }
  136.   window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  137.   }
  138.   else
  139.   {
  140.    //App is aim - in this case shift-ctrl-C which invokes cmdNewchat should bring up add Contact window.
  141.       cmdAddBuddy();
  142.   }
  143. }
  144.  
  145. /*
  146.  * Function: cmdNewIM()
  147.  *
  148.  * Arguments: None
  149.  * 
  150.  * Return: None
  151.  *
  152.  * Description: Function invoked from menu or toolbar to create a new IM 
  153.  *        window. Loads the window into a pre-connect state, e.g., the 
  154.  *        dialog consists of screen name field and an editor. This
  155.  *        function determines which buddy is selected in the list. 
  156.  *        If a buddy is selected (the first one found) and is online,
  157.  *        the screenname field in the IM window is initialized to that
  158.  *        buddy. Otherwise, the screen name field is set to "".
  159. */
  160.  
  161. function cmdNewIM()
  162. {
  163.   var screenName = getSelectedScreenName();
  164.   if (AimOnlineAway())
  165.     ComeBack();
  166.   if (!aimBuddyIsOnline(screenName))
  167.     screenName = null;
  168.     
  169.   if (screenName != null) {
  170.     var pIAimIM = aimIMObject();
  171.     if (pIAimIM)
  172.       var pWindow = pIAimIM.GetExistingIM(screenName);
  173.     if (pWindow) {
  174.       pWindow.focus();
  175.       return;
  176.     }
  177.   }
  178.   aimIMInvokeIMForm(screenName);
  179. }
  180.  
  181. /*
  182.  * Function: getSelectedBuddiesFromList()
  183.  *
  184.  * Arguments: None
  185.  * 
  186.  * Return: array of strings of buddies
  187.  *     that are currently selected (expands Groups to all buddies in group).
  188.  *
  189.  * Description: Function invoked via cmdNewChatSidebar to poll the
  190.  *        Buddy list to find out which buddies (and expanded groups are selected).
  191.  *        This function will always return an Array.
  192.  *    
  193. */
  194.  
  195. function getSelectedBuddiesFromList()
  196. {
  197.   var tree = getSelectedTreeName();
  198.   var col = getSelectedTabName();
  199.   var selectedBuddies = new Array();
  200.   var selectedGroups = new Array();
  201.   var groupCount = 0;
  202.   var buddyCount = 0;
  203.   if (!tree || !col) return;
  204.   var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  205.   if (rangeCount == 0)
  206.     return null;
  207.   var view = tree.treeBoxObject.view;
  208.   var totalRowCount = view.rowCount;
  209.   for(var i = 0; i < rangeCount; i++) {
  210.     var startIndex = {};
  211.     var endIndex = {};
  212.     tree.treeBoxObject.selection.getRangeAt(i, startIndex, endIndex);
  213.     for (var j = startIndex.value; j <= endIndex.value; j++) {
  214.       var inOffline = IsIndexinSpecialGroup(tree, col, j);
  215.       if (inOffline)
  216.         break;
  217.  
  218.       var level = view.getLevel(j);
  219.       if (level == 0) {
  220.         //ok..a group (not in offline gp) is selected.
  221.         var groupResource = GetBuddyResource(tree, j);
  222.         var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  223.         if (!CheckForDuplicateInArray(selectedGroups, groupName)) {
  224.           // we really don't need this check...but just in case ;-)
  225.           selectedGroups[groupCount++] = groupName;
  226.         }
  227.       }
  228.       else {
  229.         // ok..a buddy is selected. Make sure the group associated with this buddy is not in the selectedGroups list.
  230.         var parentIndex = view.getParentIndex(j);
  231.         var parentResource = GetBuddyResource(tree, parentIndex);
  232.         var parentName = GetBuddyAttribute(tree, parentResource, "Name");
  233.         if (!CheckForDuplicateInArray(selectedGroups, parentName)) {
  234.           var buddyResource = GetBuddyResource(tree, j);
  235.           var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  236.           if (!CheckForDuplicateInArray(selectedBuddies, buddyName)) {
  237.             selectedBuddies[buddyCount++] = buddyName;
  238.           }
  239.         }
  240.  
  241.  
  242.       }
  243.     }
  244.   }
  245.  
  246.   //till now we have all the information about the selected buddies and the groups (NOT the buddies underneath
  247.   //the selected groups.
  248.   for (var m=0; m < selectedGroups.length; m++) {
  249.     var viewIndex = GetGroupIndex(tree, col, selectedGroups[m]);
  250.     if (viewIndex < 0) {
  251.       dump("Unable to find the group index for group: " + selectedGroups[m] + "\n");
  252.       return;
  253.     }
  254.  
  255.     //open the group
  256.     if(!view.isContainerOpen(viewIndex))
  257.       view.toggleOpenState(viewIndex);
  258.  
  259.     //get the buddies
  260.     var groupIndex = viewIndex;
  261.     totalRowCount = view.rowCount;
  262.     while ((groupIndex < totalRowCount-1) && (viewIndex == view.getParentIndex(++groupIndex))) {
  263.       var buddyResource1 = GetBuddyResource(tree, groupIndex);
  264.       var buddyName1 = GetBuddyAttribute(tree, buddyResource1, "ScreenName");
  265.       if (!CheckForDuplicateInArray(selectedBuddies, buddyName1))
  266.         selectedBuddies[buddyCount++] = buddyName1;
  267.     } //while
  268.  
  269.   } //for
  270.  
  271.   return selectedBuddies;
  272. }
  273.  
  274. /* For the given parameter, this fn returns the index of the groupName */
  275. function GetGroupIndex(tree, col, groupName)
  276. {
  277.   var view = tree.treeBoxObject.view;
  278.   var totalRowCount = view.rowCount;
  279.   for (var k=0; k<totalRowCount; k++) {
  280.     var level = view.getLevel(k);
  281.     //groups are always at index 0
  282.     if (level == 0) {
  283.       var parentResource = GetBuddyResource(tree, k);
  284.       var cellText = GetBuddyAttribute(tree, parentResource, "Name");
  285.       if (cellText == groupName)
  286.         return k;
  287.     }
  288.   }
  289.   return -1;
  290. }
  291.  
  292. /* Just checks for any duplication in the array */
  293. function CheckForDuplicateInArray(aarray, element)
  294. {
  295.   for (var i=0; i<aarray.length; i++) {
  296.     if (aarray[i] == element)
  297.       return true;
  298.   }
  299.   return false;
  300. }
  301.  
  302. /*Checks for any duplicatation in the name property in an array */
  303. function CheckForDuplicateNameInArray(aarray, element)
  304. {
  305.   for (var i=0; i<aarray.length; i++) {
  306.     if (aarray[i].name == element)
  307.       return true;
  308.   }
  309.   return false;
  310. }
  311.  
  312. /* Checks whether the index is in Special group
  313.    Right now only Special group: Awaiting Authorization
  314.    Maybe later on Offline and Collected buddies will fall under this category ;-)
  315. */
  316.  
  317. function IsIndexinSpecialGroup(tree, col, index)
  318. {
  319.   var offlineIndex = -1;
  320.   var view = tree.treeBoxObject.view;
  321.   var totalRowCount = view.rowCount;
  322.   for (var k=0; k<totalRowCount; k++) {
  323.     var level = view.getLevel(k);
  324.     if (level == 0) {
  325.       var cellText = view.getCellText(k, col);
  326.       if (cellText == aimString("msg.AuthGroup")) {
  327.       
  328.         offlineIndex = k;
  329.         break;
  330.       }
  331.     }
  332.   }
  333.  
  334.   if ((index >= offlineIndex) && (offlineIndex != -1))
  335.     return true;
  336.   else
  337.     return false;
  338.  
  339. }
  340.  
  341.  
  342. /*
  343.  * Function: cmdSignOn()
  344.  *
  345.  * Arguments: None
  346.  * 
  347.  * Return: None
  348.  *
  349.  * Description: Called from menu item or toolbar. Passes control to sidebar
  350.  *        panel cmdSignOn() (see SidebarPanel/SidebarPanel.js)
  351. */
  352.  
  353. function cmdSignOn()
  354. {
  355.     //var sidebarframe = top.frames["AppPanel"];
  356.     //var sidebarframe=top.AIMDocumentPath;
  357.     var sidebarframe=getsidebarframe();
  358.  
  359.   if(sidebarframe) {
  360.       sidebarframe.cmdPanelSignOn();
  361.   }
  362.   
  363. }
  364.  
  365. /*
  366.  * Function: cmdSignOff()
  367.  *
  368.  * Arguments: None
  369.  * 
  370.  * Return: None
  371.  *
  372.  * Description: Calls aimSessionLogoff to close current IM session. 
  373.  *     
  374.  *
  375. */
  376.  
  377. function cmdSignOff()
  378. {
  379.   /* Set pref to be false so that auto login doesnt get fired for every launch */
  380.   aimPrefsManager().SetBoolPref("aim.session.appfirstlogin", false, null,true);
  381.   aimSessionLogoff();
  382.  
  383. }
  384.  
  385. /*
  386.  * Function: cmdCancelSignOn()
  387.  *
  388.  * Arguments: None
  389.  * 
  390.  * Return: None
  391.  *
  392.  * Description: Called during connection startup if cancel button is pressed.
  393.  *         Cancels the IM session by calling cmdSignOff().
  394.  *        
  395. */
  396.  
  397. function cmdCancelSignOn()
  398. {
  399.     aimPrefsManager().SetBoolPref("aim.session.firsttry", false, null, true);
  400.     cmdSignOff();
  401. }
  402.  
  403. /*
  404.  * Function: cmdClose()
  405.  *
  406.  * Arguments: None
  407.  * 
  408.  * Return: None
  409.  *
  410.  * Description: Invoked from close menu item, or from cmdSignOffAndClose(),
  411.  *        below. Causes the app window to be closed.
  412.  *
  413. */
  414.  
  415. function cmdClose()
  416. {
  417.    //aimCmdClose();
  418.    top.close();
  419. }
  420.  
  421. /*
  422.  * Function: cmdSignOffAndClose()
  423.  *
  424.  * Arguments: None
  425.  * 
  426.  * Return: None
  427.  *
  428.  * Description: Called in response to user selecting signoff and close menu
  429.  *        item. Signs off the current IM session and closes the 
  430.  *        standalone window.
  431. */
  432.  
  433. function createInstance( contractid, iidName )
  434. {
  435.     var iid = eval( "Components.interfaces." + iidName );
  436.         return Components.classes[ contractid ].createInstance( iid );
  437. }
  438.  
  439. function cmdExportBuddyList()
  440. {
  441.         nsIFilePicker = Components.interfaces.nsIFilePicker;
  442.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  443.  
  444.     fp.init(window, aimString("title.exportbudlist"), nsIFilePicker.modeSave);
  445.     fp.appendFilter(aimString("budlist.title"), aimString("budlist.filter"));
  446.     fp.appendFilters(nsIFilePicker.filterAll);
  447.  
  448.     try {
  449.         var ret = fp.show();
  450.         if ( ret == nsIFilePicker.returnOK || ret == nsIFilePicker.returnReplace) {
  451.             var status;
  452.             status = aimBuddyExportBuddyList(fp.file);
  453. /*
  454.             if ( status == false )
  455.                 aimErrorBox(aimString("msg.exporttryagain"));
  456.             else
  457.                 aimErrorBox(aimString("msg.exportsuccess"));
  458. */
  459.         }
  460.     } 
  461.     catch (ex) {
  462.         aimErrorBox(aimString("msg.exportfailure"));
  463.     }
  464.     return;
  465. }
  466.  
  467.  
  468. function cmdImportBuddyList()
  469. {
  470.  
  471.     nsIFilePicker = Components.interfaces.nsIFilePicker;
  472.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  473.  
  474.     fp.init(window, aimString("title.importbudlist"), nsIFilePicker.modeOpen);
  475.     fp.appendFilter(aimString("budlist.title"), aimString("budlist.filter"));
  476.     fp.appendFilters(nsIFilePicker.filterAll);
  477.  
  478.     try {
  479.         var ret = fp.show();
  480.         if ( ret == nsIFilePicker.returnOK ) {
  481.             var status;
  482.             aimBuddyImportBuddyList(fp.file);
  483.         }
  484.     }
  485.     catch (ex) {
  486.         aimErrorBox(aimString("msg.importfailure"));
  487.     }
  488.     return;
  489. }
  490.  
  491. function cmdSignOffAndClose()
  492. {
  493.     cmdSignOff();
  494.     cmdClose();
  495. }
  496.  
  497. /*
  498.  * Function: cmdAddBuddy()
  499.  *
  500.  * Arguments: None
  501.  * 
  502.  * Return: None
  503.  *
  504.  * Description: Called in response to menu item of toolbar button in standalone
  505.  *        for adding a buddy to a buddy group. Opens BuddyAddBuddy.xul to
  506.  *        place a dialog that can be used to add a buddy.
  507.  *
  508.  * Bugs:    Needs to support inline editing.
  509.  * 
  510. */
  511.  
  512. function cmdAddBuddy()
  513. {
  514.   var sidebarframe=getsidebarframe();
  515.     var foundOne = false;
  516.     var selectedGroup = "";
  517.   var elt = sidebarframe;
  518.   if (!sidebarframe)
  519.     elt = window;
  520.   var tree = elt.document.getElementById("ListSetup");
  521.    if (!tree )
  522.       return;
  523.  
  524.   var isGroupPresent = aimCheckForGroupCount();
  525.   if (!isGroupPresent) {
  526.     (aimString("msg.NoGroups"));
  527.       return;
  528.   }
  529.  
  530.   var groups = aimGetSelectedBuddyGroups();
  531.     openDialog("chrome://aim/content/BuddyAddBuddy.xul", "", 
  532.         "modal=yes,titlebar,chrome", groups, tree, null);
  533. }
  534.  
  535. /*
  536.  * Function: cmdAddGroup()
  537.  *
  538.  * Arguments: None
  539.  * 
  540.  * Return: None
  541.  *
  542.  * Description: Called in response to menu item of toolbar button in standalone
  543.  *        for adding a buddy group. Opens BuddyAddGroup.xul to place a 
  544.  *        dialog that can be used to add a buddy group.
  545.  *
  546.  * Bugs:    Needs to support inline editing.
  547.  * 
  548. */
  549.  
  550. function cmdAddGroup()
  551. {
  552.     openDialog("chrome://aim/content/BuddyAddGroup.xul", "", "modal=yes,titlebar,chrome");
  553. }
  554.  
  555. /*
  556.  * Function: SelectedGroup()
  557.  *
  558.  * Arguments: None
  559.  * 
  560.  * Return: None
  561.  *
  562.  * Description: Constructor function for SelectedGroup objects
  563.  *         
  564.  *        
  565. */
  566.  
  567. function SelectedGroup()
  568. {
  569.   var index = 0;
  570.     var selected = "false";
  571.     var name = null;
  572. }
  573.  
  574. /*
  575.  * Function: SelectedBuddy()
  576.  *
  577.  * Arguments: None
  578.  * 
  579.  * Return: None
  580.  *
  581.  * Description: Constructor function for SelectedBuddy objects
  582.  *         
  583. */
  584.  
  585. function SelectedBuddy()
  586. {
  587.     var parentname = null;
  588.     var name = null;
  589. }
  590.  
  591. /*
  592.  * Function: cmdDelete()
  593.  *
  594.  * Arguments: None
  595.  * 
  596.  * Return: None
  597.  *
  598.  * Description: Called in response to user clicking delete toolbar button or
  599.  *        selecting delete menu item. Deletes all selected groups (and
  600.  *        the buddies they contain) and all selected buddies.
  601. */
  602.  
  603. function cmdDelete()
  604. {
  605.   var tree = getSelectedTreeName();
  606.   var col = getSelectedTabName();
  607.   var selectedBuddies = new Array();
  608.   var selectedGroups = new Array();
  609.   var groupCount = 0;
  610.   var buddyCount = 0;
  611.   var lastSelectedIndex;
  612.   if (!tree || !col) return;
  613.   var groupCount = 0;
  614.   var buddyCount = 0;
  615.   var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  616.   if (rangeCount == 0) {
  617.     // nothing is selected
  618.     aimErrorBox(aimString("msg.NothingToDelete"));
  619.     return;
  620.   }
  621.   var view = tree.treeBoxObject.view;
  622.   for(var i = 0; i < rangeCount; i++) {
  623.     var startIndex = {};
  624.     var endIndex = {};
  625.     tree.treeBoxObject.selection.getRangeAt(i, startIndex, endIndex);
  626.     lastSelectedIndex = endIndex.value;
  627.     for (var j = startIndex.value; j <= endIndex.value; j++) {
  628.       var level = view.getLevel(j);
  629.       if (level == 0) {
  630.         var groupResource = GetBuddyResource(tree, j);
  631.         var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  632.         // Special groups like Offline have no resources. So the value will be null.
  633.         if (groupName == aimString("msg.AuthGroup")|| groupName == null) {
  634.           aimErrorBox(aimString("msg.CannotDeleteAuthGroup"));
  635.           continue;
  636.         }
  637.         
  638.         selectedGroups[groupCount] = new SelectedGroup;
  639.         selectedGroups[groupCount].name = groupName;
  640.         selectedGroups[groupCount].index = j;
  641.         groupCount++;
  642.  
  643.  
  644.  
  645.       } //if level ==0
  646.       else {
  647.         if (level == 1) {
  648.           var parentIndex = view.getParentIndex(j);
  649.           var parentResource = GetBuddyResource(tree, parentIndex);
  650.           var parentName = GetBuddyAttribute(tree, parentResource, "Name");
  651.           if (parentName == aimString("msg.AuthGroup") || parentName == null) {
  652.              // A contact from the special group Authorization awaiting has been selected.
  653.              var buddyResource = GetBuddyResource(tree, j);
  654.              var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  655.              selectedBuddies[buddyCount] = new SelectedBuddy;
  656.              selectedBuddies[buddyCount].name = buddyName;
  657.              selectedBuddies[buddyCount].parentname = aimString("msg.AuthGroup");
  658.             // a group under Offline is selected.
  659.           /*  var offlineGroupResource = GetBuddyResource(tree, j);
  660.             var offlineGroupName = GetBuddyAttribute(tree, offlineGroupResource, "Name");
  661.             if (!CheckForDuplicateNameInArray(selectedGroups, offlineGroupName)) {
  662.               selectedGroups[groupCount] = new SelectedGroup;
  663.               selectedGroups[groupCount].name = offlineGroupName;
  664.               selectedGroups[groupCount].index = j;
  665.               groupCount++;
  666.  
  667.             }
  668.            */
  669.  
  670.  
  671.           } //if offline
  672.           else {
  673.             // a Online buddy is selected
  674.             if (!tree.treeBoxObject.selection.isSelected(parentIndex)) {
  675.               //If the parent is already selected, ignore the selection. Else get the parent name
  676.               var buddyResource = GetBuddyResource(tree, j);
  677.               var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  678.               selectedBuddies[buddyCount] = new SelectedBuddy;
  679.               selectedBuddies[buddyCount].name = buddyName;
  680.               selectedBuddies[buddyCount].parentname = parentName;
  681.               buddyCount++;
  682.             } //if
  683.  
  684.  
  685.           } //else
  686.  
  687.         } //if level 1
  688.         else {
  689.           if (level == 2) {
  690.             //Offline buddy is selected..
  691.             var offlineParentIndex = view.getParentIndex(j);
  692.             if (!tree.treeBoxObject.selection.isSelected(offlineParentIndex)) {
  693.               //If the parent is already selected, ignore the selection. Else get the parent name
  694.               //get the offline parent name
  695.               var offlineParentResource = GetBuddyResource(tree, offlineParentIndex);
  696.               var offlineParentName = GetBuddyAttribute(tree, offlineParentResource, "Name");
  697.               
  698.               // if the group is already selected in the Online, ignore it.
  699.               if (!CheckForDuplicateNameInArray(selectedGroups, offlineParentName)) {
  700.                 var buddyResource = GetBuddyResource(tree, j);
  701.                 var buddyName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  702.                 selectedBuddies[buddyCount] = new SelectedBuddy;
  703.                 selectedBuddies[buddyCount].name = buddyName;
  704.                 selectedBuddies[buddyCount].parentname = offlineParentName;
  705.                 buddyCount++;
  706.               }
  707.             } //if
  708.           } //if 
  709.         } //else
  710.       } //else
  711.     } //for
  712.   } //for
  713.  
  714.  
  715.  
  716.   var answer;
  717.   var hasCancelled = 0;
  718.   for (var g=0; g<selectedGroups.length; g++) {
  719.     if (selectedGroups[g].name != null && selectedGroups[g].name != "" ) {
  720.       if (isIcq() != true ) {
  721.         answer = top.confirm(aimString("confirm.DeleteGroup").replace(/%GroupName%/, selectedGroups[g].name));
  722.         }
  723.       else {
  724.         answer = top.confirm(aimString("confirm.DeleteGroup_ICQ").replace(/%GroupName%/, selectedGroups[g].name));
  725.         }
  726.       if (answer == true)
  727.         aimBuddyRemoveBuddyGroup(selectedGroups[g].name);
  728.       else
  729.         if (!hasCancelled)
  730.           hasCancelled = 1;
  731.     }
  732.   }
  733.  
  734.   for (var b=0; b<selectedBuddies.length; b++) {
  735.     if (selectedBuddies[b].name != null && selectedBuddies[b].name != "" ) {
  736.       if (isIcq() != true ) {
  737.         answer  = top.confirm(aimString("confirm.DeleteBuddy").replace(/%BuddyName%/, selectedBuddies[b].name).replace(/%GroupName%/, selectedBuddies[b].parentname));
  738.         }
  739.       else {
  740.         answer  = top.confirm(aimString("confirm.DeleteBuddy_ICQ").replace(/%BuddyName%/, selectedBuddies[b].name).replace(/%GroupName%/, selectedBuddies[b].parentname));
  741.         }
  742.       if (answer == true) {
  743.         if (selectedBuddies[b].parentname == aimString("msg.AuthGroup")) {
  744.            // If this is the Awaiting authorization special group remove from feedbag and datasource
  745.            aimBuddyManager().RemoveBuddyAll(selectedBuddies[b].name);
  746.            aimFeedbagManager().ClearAuthorization(selectedBuddies[b].name);
  747.            continue;
  748.         }
  749.         aimBuddyRemoveBuddy(selectedBuddies[b].parentname, selectedBuddies[b].name);
  750.      }
  751.       else
  752.         if (!hasCancelled)
  753.           hasCancelled = 1;
  754.     }
  755.   }
  756.  
  757.   var totalRowCount = view.rowCount;
  758.   if (!hasCancelled) {
  759.     // The view maintains the selection if the user has cancelled the deletion. So don't worry about selecting the
  760.     // next index in this case
  761.     if ((lastSelectedIndex + 1) > totalRowCount)
  762.       //if there is nothing after the last selected one, select the last one.
  763.       SelectIndex(totalRowCount-1);
  764.     else
  765.       SelectIndex(lastSelectedIndex);
  766.   }
  767.  
  768. }
  769.  
  770.  
  771.  
  772. function cmdAbEditCard()
  773. {
  774.   var sidebarframe=getsidebarframe();
  775.   var selectedGroup = "";
  776.   var wasSelected = false;
  777.   var tree = sidebarframe.document.getElementById("ListSetup");
  778.     var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");   
  779.     // in the online tab and the user hit delete
  780.   if ( tab.selectedIndex == 0 )
  781.     return;
  782.   var groups = aimBuddyTreeFindGroups( tree );
  783.   top.selectedGroups = new Array();
  784.   for (var i = 0; i != groups.length; i++) {
  785.   // make a record for this group
  786.     top.selectedGroups[i] = new SelectedGroup;
  787.     top.selectedGroups[i].selectedBuddies = new Array();
  788.     top.selectedGroups[i].name = groups[i].getAttribute("Name");
  789.     if (groups[i].getAttribute("selected") == "true") {
  790.       wasSelected = "true";
  791.       top.selectedGroups[i].selected = "true";
  792.     }
  793.     else
  794.       top.selectedGroups[i].selected = "false";                                                   // find the buddy nodes for this group.
  795.  
  796.     var buddies = null;
  797.     for (var j = 0; j != groups[i].childNodes.length; j++)
  798.     {
  799.       if (groups[i].childNodes[j].nodeName == "treechildren")
  800.       {
  801.         // found it.
  802.         buddies = groups[i].childNodes[j].childNodes;
  803.         break;
  804.       }
  805.     }
  806.  
  807.     if (buddies)
  808.     {
  809.       for (var j = 0; j != buddies.length; j++)
  810.       {
  811.         top.selectedGroups[i].selectedBuddies[j] = new SelectedBuddy;
  812.         if (buddies[j].getAttribute("selected") == "true") {
  813.           // buddy is selected. Save the name
  814.           // and set the selected flag to true
  815.           wasSelected = "true";
  816.           top.selectedGroups[i].selectedBuddies[j].name = buddies[j].getAttribute("ScreenName");
  817.           top.selectedGroups[i].selectedBuddies[j].selected = "true";
  818.         }
  819.         else
  820.           top.selectedGroups[i].selectedBuddies[j].selected = "false";
  821.       }
  822.     }                     
  823.     }
  824.  
  825.   for ( var i = 0; i != top.selectedGroups.length; i++ ) {
  826.     selectedGroup = top.selectedGroups[i].name;
  827.     if ( top.selectedGroups[i].selected == "true" ) {
  828.          aimErrorBox(aimString("msg.SelectBuddy")); 
  829.         }
  830.     else {
  831.       for ( var j = 0; j != top.selectedGroups[i].selectedBuddies.length; j++ ) {
  832.         if ( top.selectedGroups[i].selectedBuddies[j].selected == "true" ) {
  833.           selectedBuddy = top.selectedGroups[i].selectedBuddies[j].name;
  834.           if ( selectedBuddy && selectedBuddy != "" ) {
  835.             // XXX DOES THIS STILL WORK, IS IT STILL NEEDED?
  836.                   var card = aimABInfo().getPersonalAbCardFromAttribute("_AimScreenName", selectedBuddy, false);
  837.               goEditCardDialog("moz-abmdbdirectory://abook.mab",card,null);
  838.           }
  839.         }                  
  840.         }
  841.     }
  842.   }
  843.  
  844. }       
  845.  
  846.  
  847. function cmdCustom()
  848. {
  849.   url = aimString("app.custom.url");
  850.   aimCmdNewBrowser(url);
  851. }
  852.  
  853. function cmdAdClick()
  854. {
  855.      aimCmdNewBrowser(aimRegionString("app.ad.link"));
  856.   }
  857.  
  858. var ad_access=1;
  859.  
  860. function setAdTimer()
  861. {
  862.  
  863.   var adButton = top.document.getElementById("adButton");
  864.     var adImage = aimRegionString("app.ad.image")+"?access=" + ad_access;
  865.  
  866.   ad_access++;
  867.   var adTimer = aimString("app.ad.timer");
  868.  
  869.   if(adButton)
  870.         adButton.setAttribute("src", adImage);
  871.  
  872.   if(window)
  873.     window.setTimeout('setAdTimer()', adTimer);
  874. }
  875.  
  876. function getSidebarDs()
  877. {
  878. var PANELS_RDF_FILE = "UPnls";
  879. try {
  880.      var locator_service = Components.classes["@mozilla.org/file/directory_service;1"].getService();
  881.       if (locator_service)
  882.         locator_service = locator_service.QueryInterface(Components.interfaces.nsIProperties);
  883.       var sidebar_file = locator_service.get(PANELS_RDF_FILE, Components.interfaces.nsIFile);
  884.       if (!sidebar_file.exists()) {
  885.         //Sidebar panels file does not exist?
  886.         return;
  887.       }
  888.         var file_url = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  889.         file_url.file = sidebar_file;
  890.         return file_url.spec;
  891.     } catch (ex) {
  892.        throw(ex);
  893.     }
  894.  }
  895.  
  896. function CheckBuddyPanel()
  897. {
  898.   var RDF = aimRDF();
  899.   this.nc = "http://home.netscape.com/NC-rdf#";
  900.   this.resource = 'urn:sidebar:current-panel-list';
  901.     var panel_list =RDF.GetDataSource(getSidebarDs()).GetTarget(RDF.GetResource("urn:sidebar:current-panel-list"),RDF.GetResource("http://home.netscape.com/NC-rdf#"+"panel-list"),  true);
  902.     if (panel_list) {
  903.         panel_list.QueryInterface(Components.interfaces.nsIRDFResource);
  904.     }
  905.   var container = Components.classes["@mozilla.org/rdf/container;1"].createInstance();
  906.     try { 
  907.     container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
  908.     container.Init(RDF.GetDataSource(getSidebarDs()), panel_list);
  909.     const RDF_CONTRACTID = "@mozilla.org/rdf/rdf-service;1";
  910.     const nsIRDFService = Components.interfaces.nsIRDFService;
  911.     this.datasource = RDF.GetDataSource(getSidebarDs());
  912.     this.rdf = Components.classes[RDF_CONTRACTID].getService(nsIRDFService);
  913.   } catch (ex)
  914.   {
  915.     if (timercatch == false)
  916.     {
  917.       timercatch = true;
  918.       setTimeout("CheckBuddyPanel()",5000);
  919.     }
  920.     
  921. //    throw(ex);
  922.   }
  923.     var panel_resource = RDF.GetResource("urn:sidebar:panel:im-panel");
  924.     var im_resource=RDF.GetResource("urn:sidebar:3rdparty-panel:chrome://aim/content/SidebarPanel.xul");
  925.     var panel_index = container.IndexOf(panel_resource);
  926.     var panel_index2 = container.IndexOf(im_resource);
  927.     if ((panel_index == -1) && (panel_index2==-1))
  928.     {
  929.       if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
  930.     { 
  931. //  This line was broken by mstoltz's security fix to disallow chrome urls passed to addPanel
  932. //  Eventually when the security fix is done properly (i.e. checking the caller rather than blindly disallowing chrome)
  933. //  We should use this addPanel call and back out all the changes I made to this file in this checkin.
  934. //         window.sidebar.addPanel ("Buddy List","chrome://aim/content/SidebarPanel.xul",""); 
  935.  
  936.       var aTitle = "Buddy List";
  937.       var aContentURL = "chrome://aim/content/SidebarPanel.xul";
  938.  
  939.       this.datasource.Assert(panel_resource,
  940.                              this.rdf.GetResource(this.nc + "title"),
  941.                              this.rdf.GetLiteral(aTitle),
  942.                              true);
  943.       this.datasource.Assert(panel_resource,
  944.                             this.rdf.GetResource(this.nc + "content"),
  945.                             this.rdf.GetLiteral(aContentURL),
  946.                             true);
  947.       container.AppendElement(panel_resource);
  948.       // Use an assertion to pass a "refresh" event to all the sidebars.
  949.       // They use observers to watch for this assertion (in sidebarOverlay.js).
  950.       this.datasource.Assert(this.rdf.GetResource(this.resource),
  951.                              this.rdf.GetResource(this.nc + "refresh"),
  952.                              this.rdf.GetLiteral("true"),
  953.                              true);
  954.       this.datasource.Unassert(this.rdf.GetResource(this.resource),
  955.                                this.rdf.GetResource(this.nc + "refresh"),
  956.                                this.rdf.GetLiteral("true"));
  957.  
  958.       /* Write the modified panels out. */
  959.       const nsIRDFRemoteDataSource = Components.interfaces.nsIRDFRemoteDataSource;
  960.       this.datasource.QueryInterface(nsIRDFRemoteDataSource).Flush();
  961.       }
  962.     } 
  963.   SidebarSelectPanel(document.getElementById("urn:sidebar:panel:im-panel"), false, false);
  964. }
  965.  
  966.  
  967.  /******
  968.   * Request info about a user and display it in a tooltip (after callback).
  969.   ******/
  970.  
  971. function fillInfoTooltip(aEvent, aTooltipNode)
  972. {
  973.   var tree = document.getElementById("OnlineBuddies");
  974.   var bx = tree.treeBoxObject;
  975.   var row = {}; var col = {}; var obj = {};
  976.   bx.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
  977.   var rowValue = row.value;
  978.   var tooltip = document.getElementById("infoTooltip");
  979.   if (rowValue < 0) {
  980.     tooltip.setAttribute("collapsed", "true");
  981.     return;
  982.   }
  983.   var buddyResource = GetBuddyResource(tree, rowValue);
  984.   var name = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  985.   var view = tree.treeBoxObject.view;
  986.   var level = view.getLevel(rowValue);
  987.   var inOffline = IsIndexinSpecialGroup(tree, col.value, rowValue);
  988.   if (level != 1 || inOffline) {
  989.     // if this is a mac do this bad hack to hide the tooltip
  990.     if (navigator.appVersion.indexOf("Macintosh") != -1)
  991.       document.getElementById("hideload").setAttribute("collapsed", "true");
  992.     else
  993.       tooltip.setAttribute("collapsed", "true");
  994.     return;
  995.   }
  996.   
  997.    // this check is required to prevent redundant 
  998.    // re-requests while waiting for the callback
  999.    if (!rowValue._RequestingInfo) {
  1000.      //var name = getScreenNameFromNode(aTreecell);
  1001.      //var tooltip = document.getElementById("infoTooltip");
  1002.  
  1003.      if (name && name != "" && tooltip) {
  1004.        var elOnline = document.getElementById("infoTooltipOnlineTime");
  1005.        elOnline.setAttribute("value", "");
  1006.        var elStatusTime = document.getElementById("infoTooltipStatusTime");
  1007.        elStatusTime.setAttribute("value", "");
  1008.        // if this is a mac do this bad hack to hide the tooltip
  1009.        if (navigator.appVersion.indexOf("Macintosh") != -1)
  1010.          document.getElementById("hideload").setAttribute("collapsed", "true");
  1011.        else
  1012.          tooltip.setAttribute("collapsed", "true");
  1013.        rowValue._RequestingInfo = true;
  1014.  
  1015.        // send the request and wait for callback
  1016.        var listenerCap = new TooltipCapListener(rowValue, tooltip);
  1017.        try {
  1018.         aimLocateManager().RequestUserInfoCapabilities(listenerCap, name);
  1019.        } catch (ex) {
  1020.          //ERROR: unable to retrieve AIM user info for name
  1021.          return;
  1022.        }
  1023.      }
  1024.    }
  1025.  }
  1026.  
  1027.  /******
  1028.   * Search up the tree for first treeitem node.
  1029.   ******/
  1030.  
  1031.  function getScreenNameFromNode(aNode)
  1032.  {
  1033.    var node = aNode;
  1034.    while (node.localName != "treeitem") {
  1035.      node = node.parentNode;
  1036.    }
  1037.    return node ? node.getAttribute("ScreenName") : null;
  1038.  }
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  /******
  1044.   * Event listener used for RequestUserInfoCapabilities
  1045.   ******/
  1046.  
  1047.  function TooltipCapListener(aTreecell, aTooltip)
  1048.  {
  1049.    this.mTreecell = aTreecell;
  1050.    this.mTooltip = aTooltip;
  1051.  }
  1052.  
  1053.  TooltipCapListener.prototype = {
  1054.     OnRequestUserInfoCapabilitiesComplete: function(aScreenName, aUserObj)
  1055.      {
  1056.      var now = new Date().getTime()/1000;
  1057.      // TODO: search within mTooltip for text elements instead of id search
  1058.      
  1059.      // fill the screen name
  1060.      var elName = document.getElementById("infoTooltipName");
  1061.   
  1062.      aimABInfo = aimManager().QueryInterface(Components.interfaces.nsIAimABInfo);
  1063.      if (aimABInfo) {
  1064.         var card = aimABInfo.getPersonalAbCardFromAttribute("_AimScreenName", aScreenName, false);
  1065.         if (card) {
  1066.           if (card.nickName)
  1067.             elName.setAttribute("value", card.nickName);
  1068.           else if (card.displayName)
  1069.             elName.setAttribute("value", card.displayName);
  1070.                else
  1071.             elName.setAttribute("value", aScreenName);
  1072.           }
  1073.           else
  1074.           elName.setAttribute("value", aScreenName);
  1075.      }
  1076.      else
  1077.        elName.setAttribute("value", aScreenName);
  1078.  
  1079.      
  1080.    // fill the online line
  1081.    var elOnline = document.getElementById("infoTooltipOnlineTime");
  1082.    var since = aUserObj.GetOnlineSinceTime();
  1083.    elOnline.setAttribute("value", getPrettyDateDiff(now, since));
  1084.      var elOnlineId = document.getElementById("infoTooltipOnlineTimeId");
  1085.    elOnlineId.setAttribute("value", aimString("tooltip.online") + ":");
  1086.    
  1087.    // fill the status line
  1088.    var elStatus = document.getElementById("infoTooltipStatus");
  1089.      var elStatusTime = document.getElementById("infoTooltipStatusTime");
  1090.    if (aUserObj.IsIdle()) {
  1091.      elStatus.setAttribute("value", aimString("tooltip.idle") + ":");
  1092.      var statusDate = aUserObj.GetIdleSinceTime();
  1093.      elStatusTime.setAttribute("value", getPrettyDateDiff(now, statusDate));
  1094.    } else if (aUserObj.IsAway()) {
  1095.        elStatus.setAttribute("value", aimString("tooltip.status") + ":");
  1096.      elStatusTime.setAttribute("value", aimString("tooltip.away"));
  1097.    } else {
  1098.       elStatus.setAttribute("value", aimString("tooltip.status") + ": ");
  1099.     elStatusTime.setAttribute("value", aimString("tooltip.active"));
  1100.    }
  1101.    
  1102.    if (isIcq() != true ) 
  1103.    {  
  1104.      // fill the warnings line
  1105.      var warnings = document.getElementById("infoTooltipWarnings");
  1106.      warnings.setAttribute("value", aUserObj.GetWarningPercent() + "%");
  1107.        var warningsId = document.getElementById("infoTooltipWarningsId");
  1108.      warningsId.setAttribute("value", aimString("tooltip.warnings") + ":");
  1109.      var cp = new String(aScreenName);
  1110.      if ((cp.charCodeAt(0) > 47) && (cp.charCodeAt(0) < 58)) 
  1111.      {
  1112.       // is an icq number, do not show warnings
  1113.       warningsId.setAttribute("hidden", "true");
  1114.       warnings.setAttribute("hidden", "true");
  1115.      }
  1116.      else
  1117.      {
  1118.       warningsId.setAttribute("hidden", "false");
  1119.       warnings.setAttribute("hidden", "false");
  1120.      }
  1121.  
  1122.      
  1123.   // fill in the Service Type (AOL, Internet, Administrator...)     
  1124.      var elFlagService = document.getElementById("infoTooltipFlagValue");
  1125.      var flagServiceValue = aUserObj.GetFlags();
  1126.      var serviceString = "";
  1127.      var serviceEnums = Components.interfaces.nsAimServiceTypes;
  1128.      if (flagServiceValue & serviceEnums.Transient)
  1129.         serviceString = aimString("IdsflagTrial.label") + " ";
  1130.      if (flagServiceValue & serviceEnums.Aol)
  1131.         serviceString = serviceString + aimString("IdsflagAol.label") + " ";
  1132.      if (flagServiceValue & serviceEnums.Free)
  1133.         serviceString = serviceString + aimString("IdsflagInternet.label") + " ";
  1134.      if (flagServiceValue & serviceEnums.Administrator)
  1135.         serviceString = serviceString + aimString("IdsflagAdministrator.label") + " ";
  1136.      
  1137.    elFlagService.setAttribute("value", serviceString);
  1138.      var elFlagServiceId = document.getElementById("infoTooltipFlag");
  1139.    elFlagServiceId.setAttribute("value", aimString("tooltip.service") + ":");
  1140.    elFlagService.setAttribute("hidden", "false");
  1141.    elFlagServiceId.setAttribute("hidden", "false");
  1142.  
  1143.      
  1144.   // fill in the Capabilities
  1145.     var elCapabilities = document.getElementById("capabilitiesValue");
  1146.   var elCapabilitiesId = document.getElementById("capabilities");
  1147.   elCapabilitiesId.setAttribute("hidden", "false");
  1148.   elCapabilities.setAttribute("hidden", "false");
  1149.     try {
  1150.         var capMask = aUserObj.GetCapabilities();
  1151.     if (capMask == 0) {
  1152.       elCapabilitiesId.setAttribute("hidden", "true");
  1153.       elCapabilities.setAttribute("hidden", "true");
  1154.     } else {
  1155.       var capEnums = Components.interfaces.nsAimCapabilitesMask;
  1156.       var capString = "";
  1157.         if (capEnums.buddyIcon & capMask) {
  1158.           if (capString == "")
  1159.             // if it is the first capability, just add it
  1160.             capString += aimString("tooltip.buddyicon");
  1161.           else
  1162.             // if some capability already present just add a comma and the capability
  1163.             capString += ", " + aimString("tooltip.buddyicon");
  1164.         }
  1165.         if (capEnums.chat & capMask) {
  1166.           if (capString == "")
  1167.             capString += aimString("tooltip.chat");
  1168.           else
  1169.             capString += ", " + aimString("tooltip.chat");
  1170.         }
  1171.         if (capEnums.filexfer & capMask) {
  1172.           if (capString == "")
  1173.             capString += aimString("tooltip.filexfer");
  1174.           else
  1175.             capString += ", " + aimString("tooltip.filexfer");
  1176.         }
  1177.         if (capEnums.unification & capMask) {
  1178.           if (capString == "")
  1179.             capString += aimString("tooltip.unification");
  1180.           else
  1181.             capString += ", "+aimString("tooltip.unification");
  1182.         }
  1183.          
  1184.       elCapabilities.setAttribute("value", capString);
  1185.       elCapabilitiesId.setAttribute("value", aimString("tooltip.capabilities") + ":");
  1186.     }
  1187.     } catch (e) {}
  1188.   
  1189.       // fill the Display Name line
  1190.   var dnValue = document.getElementById("displayNameValue");
  1191.   var curDispName = aimFeedbagManager().GetDispName(aScreenName);
  1192.   var displayName = document.getElementById("displayName");
  1193.   if (curDispName != null) {
  1194.     dnValue.setAttribute("value", curDispName);
  1195.     displayName.setAttribute("value", aimString("tooltip.displayName") + ":");
  1196.     displayName.setAttribute("hidden", "false");
  1197.     dnValue.setAttribute("hidden", "false");
  1198.   }
  1199.   else {
  1200.     displayName.setAttribute("hidden", "true");
  1201.     dnValue.setAttribute("hidden", "true");
  1202.   }
  1203.  
  1204.    
  1205.      
  1206.  
  1207.   } //end if icq
  1208.   else
  1209.   {
  1210.     //Hide warning capabilities etc in Icq     
  1211.     document.getElementById("infoTooltipWarningsId").setAttribute("hidden", "true");
  1212.     document.getElementById("infoTooltipWarnings").setAttribute("hidden", "true");
  1213.     document.getElementById("infoTooltipFlag").setAttribute("hidden", "true");
  1214.     document.getElementById("infoTooltipFlagValue").setAttribute("hidden", "true");
  1215.     document.getElementById("capabilitiesValue").setAttribute("hidden", "true");
  1216.     document.getElementById("capabilities").setAttribute("hidden", "true");
  1217.     
  1218.   }
  1219.  
  1220.      // show the tooltip
  1221.      // if this is a mac do this bad hack to hide the tooltip
  1222.      if (navigator.appVersion.indexOf("Macintosh") != -1)
  1223.          document.getElementById("hideload").removeAttribute("collapsed");
  1224.      else
  1225.          this.mTooltip.removeAttribute("collapsed");
  1226.      this.mTreecell._RequestingInfo = false;
  1227.      },
  1228.  
  1229.     OnRequestUserInfoCapabilitiesError: function(aScreenName, aError)
  1230.      {
  1231.      this.mTreecell._RequestingInfo = false;
  1232.      }
  1233.  };
  1234.  
  1235.  
  1236. function cmdChangePassword() {
  1237.     window.openDialog('chrome://aim/content/AimChangePassword.xul','','modal=no,titlebar,chrome,centerscreen',null);
  1238. }
  1239.  
  1240. function cmdConfirmAccount() {
  1241.     window.openDialog('chrome://aim/content/AimConfirmAccount.xul','','modal=yes,titlebar,chrome,centerscreen',null);
  1242. }
  1243.  
  1244. function cmdChangeEmail() {
  1245.     window.openDialog('chrome://aim/content/AimChangeEmail.xul','','modal=no,titlebar,chrome,centerscreen',null);
  1246. }
  1247.  
  1248. function cmdGetMemberInfo() {
  1249.   var screenName = getSelectedScreenName();
  1250.   window.openDialog('chrome://aim/content/GetMemberInfo.xul','_blank','chrome,all,dialog=no', screenName);
  1251. }
  1252.  
  1253.  
  1254. /*
  1255. * Name: cmdBuddyAlert
  1256. * Arguments: none. 
  1257. * Description: This function is called by command handler of cmd_buddyAlert. It chooses the appropriate tree where
  1258. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it opens
  1259. * the BuddyAlert dialog by passign the screenname as an argument.
  1260. * Return Value: none
  1261. * Author: Prassanna<prass@netscape.com> 
  1262. */
  1263.  
  1264. function cmdBuddyAlert(isedit) {
  1265.   var screenName = getSelectedScreenName();
  1266.   if (screenName && (screenName != null)) 
  1267.   {
  1268.     if (isedit == 1)
  1269.       window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, 1);
  1270.     else  
  1271.       window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, null);
  1272.   }
  1273. }
  1274.  
  1275. /*
  1276. * Name: cmdDelBuddyAlert
  1277. * Arguments: none. 
  1278. * Description: This function is called by command handler of cmd_delbuddyAlert. It chooses the appropriate tree where
  1279. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it removes 
  1280. * the screen name from the buddy alert list.
  1281. * Return Value: none
  1282. * Author: Prassanna<prass@netscape.com> 
  1283. */
  1284.  
  1285. function cmdDelBuddyAlert() {
  1286.   var screenName = getSelectedScreenName();
  1287.   if (screenName && (screenName != null))
  1288.     aimBuddyManager().DeleteBuddyFromAlertList(screenName); 
  1289. }
  1290.  
  1291. function cmdNewAway()
  1292. {
  1293.   if (isIcq() == true )
  1294.     window.openDialog("chrome://aim/content/AddIcqAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  1295.   else
  1296.     window.openDialog("chrome://aim/content/AddAwayMessage.xul","_blank", "chrome,close,titlebar,modal", "", "", "");
  1297. }
  1298.  
  1299. function sendFile()
  1300. {
  1301.   window.openDialog("chrome://aim/content/sendfile.xul","_blank", "chrome,close,titlebar", "", "", "");
  1302. }
  1303.  
  1304. function addAppSessionListener() {
  1305.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1306.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1307.   if (observerService) {
  1308.     observerService.addObserver(sessionAppObserver, "sessionMode-changed", false);
  1309.   } else {
  1310.     dump("failed to get observer service\n");
  1311.   }
  1312. }
  1313.  
  1314. function removeAppSessionListener() {
  1315.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  1316.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  1317.   if (observerService)
  1318.   {
  1319.   observerService.removeObserver(sessionAppObserver, "sessionMode-changed");
  1320.   }
  1321. }
  1322.  
  1323.  
  1324. var sessionAppObserver = {
  1325.   observe: function(subject, message, data) {
  1326.   if (message == 'sessionMode-changed') {
  1327.      // Update sessionMode attribut which updates all images thru css
  1328.      window.document.getElementById("sessionAppWatcher").setAttribute("sessionMode", data);
  1329.      UpdateAppMenus(data);
  1330.      }
  1331.   }
  1332. }
  1333.  
  1334.  
  1335. function cmdRegistUser()
  1336. {
  1337.  // Open regist user url;
  1338.   regLink = aimString("icq.register.url");
  1339.   dump("SURESH: regLink = " + regLink + "\n");
  1340.   openTopWin(regLink);  
  1341.   return;
  1342. }
  1343.  
  1344. function updateCurrentAppWindow()
  1345. {
  1346.   var connectionName;
  1347.   connectionName = aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);       
  1348.   if (connectionName == "ICQ")
  1349.   {
  1350.     // Change the sessionMode to Icq. Originally in xul it was initialized to Aim by default.
  1351.     window.document.getElementById("sessionAppWatcher").setAttribute("sessionMode", "Icq");
  1352.     UpdateAppMenus("Icq");
  1353.   }
  1354. }
  1355.  
  1356. function UpdateAppMenus(sessionName)
  1357. {
  1358.   switch (sessionName) {
  1359.         case "Icq": document.getElementById('menu_File_Icq').removeAttribute("hidden");
  1360.                     document.getElementById('menu_File').setAttribute("hidden", "true");
  1361.                     document.getElementById('editOptionsid_Icq').removeAttribute("hidden");
  1362.                     document.getElementById('editOptionsid').setAttribute("hidden", "true");
  1363.                     break;
  1364.         case "Aim": document.getElementById('menu_File_Icq').setAttribute("hidden", "true");
  1365.                     document.getElementById('menu_File').removeAttribute("hidden");
  1366.                     document.getElementById('editOptionsid_Icq').setAttribute("hidden", "true");
  1367.                     document.getElementById('editOptionsid').removeAttribute("hidden");
  1368.                     break;   
  1369.   }
  1370.   
  1371. }
  1372.  
  1373. /*
  1374.  * Name: cmdRename
  1375.  * Arguments: none. 
  1376.  * Description: This function is called by command handler of cmd_rename. It opens the add buddy dialog from which user can remane
  1377.  * Return Value: none
  1378.  * Author: Prassanna<prass@netscape.com> 
  1379.  */
  1380.  
  1381. function cmdRename()
  1382. {
  1383.    var user=getSelectedScreenName();
  1384.    var tree = getSelectedTreeName();
  1385.    var currentIndex = tree.currentIndex;
  1386.    var rangeCount = tree.treeBoxObject.selection.getRangeCount();
  1387.    if (rangeCount > 1 || rangeCount < 1) { 
  1388.      // We dont support multiple selectetion for rename :-(
  1389.      aimErrorBox(aimString("msg.SelectContact"));
  1390.      return;
  1391.      }
  1392.    var view = tree.treeBoxObject.view;
  1393.    var parentIndex = view.getParentIndex(currentIndex);
  1394.    if (currentIndex > 0) {
  1395.        var groupResource = GetBuddyResource(tree, parentIndex);
  1396.        var groupName = GetBuddyAttribute(tree, groupResource, "Name");
  1397.    }
  1398.    if (user) {
  1399.      openDialog("chrome://aim/content/RenameBuddy.xul", "", "modal=yes,titlebar,chrome,centerscreen", groupName, user);
  1400.    }
  1401.    else
  1402.      aimErrorBox(aimString("msg.SelectContact"));
  1403. }
  1404.  
  1405.  
  1406. /*
  1407. * Name: cmdRequestAuth
  1408. * Arguments: none. 
  1409. * Description: This function is called by command handler of cmd_rerequest auth. It chooses the appropriate tree where
  1410. * the event is triggered from and checks to see if there is a screenName attribute on the selected node. Then it opens
  1411. * the authorization request window with the screenname.
  1412. * Return Value: none
  1413. * Author: Prassanna<prass@netscape.com> 
  1414. */
  1415.  
  1416. function cmdRequestAuth()
  1417. {
  1418.   var auth_msg=aimString("icq.rerequestauth");
  1419.   var user=getSelectedScreenName();
  1420.   var isinlist = new Object();
  1421.   aimFeedbagManager().IsInAuthList(user, isinlist);
  1422.    // Ifin auth await group open rerequest auth window
  1423.   if (isinlist.value == true) {
  1424.     window.openDialog('chrome://aim/content/icqAuthOutgoing.xul','_blank','chrome,all,dialog=no',user, auth_msg);
  1425.     }
  1426.   else
  1427.     aimErrorBox(aimString("msg.authtryagain"));  
  1428. }